﻿package rd.hardcore 
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IOErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	/**
	 * ...
	 * @author Romain Prache
	 */
	public class Datas extends EventDispatcher
	{
		
		static public const DATAS_READY : String = "datas_ready";
		
		private var urlLoader:URLLoader;
		
		static public var datas : XML;
		
		public function Datas() 
		{
			urlLoader = new URLLoader();
			urlLoader.load(new URLRequest("xml/tracks.xml"));
			urlLoader.addEventListener(Event.COMPLETE, complete);
			urlLoader.addEventListener(IOErrorEvent.IO_ERROR, fail);
		}
		
		private function fail(e:IOErrorEvent):void 
		{
			trace("\!# F A I L #!/");
		}
		
		private function complete(e:Event):void 
		{
			trace("Datas : Complete \o/");
			datas = new XML(urlLoader.data);
			dispatchEvent(new Event(DATAS_READY));
		}
		
	}
	
}